package com.sanjiahantang.youjiarole.module.common.views.impl;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.module.common.beans.CustomerBean;
import com.sanjiahantang.youjiarole.module.common.presenters.MeAccountPresenter;
import com.sanjiahantang.youjiarole.module.common.views.MeAccountView;

import java.util.List;

/**
 * 我的客户
 * Created by admin on 2017/10/29.
 */

public class MyCoustomerActivity extends BaseMvpActivity<MeAccountView, MeAccountPresenter> implements MeAccountView, View.OnClickListener {
    private ListView detail_list;
    QuickAdapter<CustomerBean.Item> adapter;
    View rll_top, fl_Left,flIcon1;
    private RadioButton rbAll, rbUnPay, rbPartPay;
    TextView title;
    ImageView icon1;
    private String type = "";

    @Override
    public MeAccountPresenter initPresenter() {
        return new MeAccountPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_me_account_detail);
        detail_list = (ListView) findViewById(R.id.detail_list);
        rll_top = findViewById(R.id.rll_top);
        rll_top.setVisibility(View.VISIBLE);
        fl_Left = findViewById(R.id.fl_Left);
        icon1= (ImageView) findViewById(R.id.icon1);
        title = (TextView) findViewById(R.id.title);
        rbAll = (RadioButton) findViewById(R.id.rbAll);
        rbUnPay = (RadioButton) findViewById(R.id.rbUnPay);
        rbPartPay = (RadioButton) findViewById(R.id.rbPartPay);
        fl_Left.setOnClickListener(this);
        flIcon1=findViewById(R.id.flIcon1);
        flIcon1.setOnClickListener(this);
        rbAll.setOnClickListener(this);
        rbUnPay.setOnClickListener(this);
        rbPartPay.setOnClickListener(this);
        icon1.setVisibility(View.VISIBLE);
        icon1.setImageDrawable(getResources().getDrawable(R.drawable.i_search));
        title.setText("我的客户");
        presenter.onLoadCustomer($this, "","");
    }

    @Override
    public void initData() {

        presenter.setOncliclkLisener(new OnLoadListener() {
            @Override
            public void onLoad(Object content) {
                Object[] param = (Object[]) content;
                switch ((int) param[0]) {
                    case ACCOUNT_TYPE_COMMEN:
                        adapter = new QuickAdapter<CustomerBean.Item>($this, R.layout.item_partner, (List<CustomerBean.Item>) param[1]) {
                            @Override
                            protected void convert(BaseAdapterHelper helper, CustomerBean.Item item) {

                                helper.setText(R.id.txtAddress,item.getAddress());
                                helper.setVisible(R.id.tagGroup,false);
                                helper.setText(R.id.txtRolePhone,"("+item.getCustomerPhone()+")");
                                helper.setText(R.id.txtRoleName, item.getUserName());
                                int color = 0;
                                String A=item.getState();
                                switch (A){
                                    case "未绑定":
                                        color=getResources().getColor(R.color.red);
                                        break;
                                    case "已绑定":
                                        color=getResources().getColor(R.color.gray);
                                        break;
                                }
                                helper.setTextColor(R.id.txtCity,color);
                                helper.setText(R.id.txtCity,A);
                            }
                        };
                        detail_list.setAdapter(adapter);
                        break;

                }
            }
        });
    }

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rbAll:
            case R.id.flAll://全部
                checkStatusRadio(rbAll, "");
                break;
            case R.id.rbUnPay:
            case R.id.flUnPay://已绑定
                checkStatusRadio(rbUnPay, "1");
                break;
            case R.id.rbPartPay:
            case R.id.flPartPay://未绑定
                checkStatusRadio(rbPartPay,"0");
                break;
            case R.id.fl_Left:
                finish();
                break;
            case R.id.flIcon1:
                startActivityForResult(new Intent($this,SearchActivity.class).putExtra(KEY_TYPE,SEARCH_TYPE_CUSTOMER),INTENT_SEARCH);
                break;

        }
    }

    private void checkStatusRadio(RadioButton rb, String type) {
        rbAll.setChecked(false);
        rbUnPay.setChecked(false);
        rbPartPay.setChecked(false);
        rb.setChecked(true);
        this.type = type;
        presenter.onLoadCustomer($this, type,"");
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK){
            switch (requestCode){
                case INTENT_SEARCH:
                    presenter.onLoadCustomer($this,type,data.getStringExtra(KEY_KEYWORDS));
                    break;
            }
        }
    }
}
